home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: October, 2000
- // Author: bb
- //
- // Procedure Name:
- // autoCreateCharacter
- //
- // Description:
- // Automatically create that contains the animated channels of
- // the object. If the animated channels are already in a character,
- // return the name of the existing character. If the animated channels
- // are not in a character, but the object is in a character, add the
- // channels to the existing character.
- //
- // Input Arguments:
- // $version: The version of this option box. Used to know how to
- // interpret the $args array.
- // "1" : $name
- //
- // $args
- // Version 1: no args
- // Version 2:
- // $args[0] = $hierarchy: whether to include the hierarchy when
- // creating the character
- //
- // Return Value:
- // New character name
- //
-
-
- global proc string autoCreateCharacter( string $version,
- string $args[] )
- {
- string $newCharacter = "";
- string $membersToAdd[];
- string $existingChars[];
- string $otherChars[];
- int $memberCount = 0;
- int $chCount = 0;
- string $obj, $ch;
-
- // check what is selected
- //
- string $sel[] = `ls -sl`;;
- string $selInit[];
- if (size($sel) == 0) {
- error("Nothing is selected.");
- return "";
- }
-
- // the hierarchy option was introduced in the 2nd version of this script
- //
- int $versionNo = $version;
- int $hierarchy = 0;
- if ($versionNo >= 2) {
- $hierarchy = $args[0];
- }
-
- if ($hierarchy) {
- select -hi $sel;
- $selInit = $sel;
- $sel = `ls -sl`;
- }
-
- // loop through the selected objects to find the animated channels
- // and the existing characters on the selected objects
- //
- for ($obj in $sel) {
- string $animPlugs[] = `listConnections -type animCurve -skipConversionNodes true -plugs true -d false -s true -c true $obj`;
- string $animNodes[] = `listConnections -type animCurve -skipConversionNodes true -plugs false -d false -s true -c true $obj`;
- string $chars[] = `listConnections -s false -d true -type character $obj`;
-
- // First find the animatable plugs
- //
- int $n_anim = size($animPlugs);
- int $ii;
- for ($ii = 0; $ii < $n_anim; $ii += 2) {
- string $animIn[] = `listConnections -s true -d false $animNodes[$ii+1]`;
- if (0 == size($animIn)) {
- $membersToAdd[$memberCount++] = $animPlugs[$ii];
- for ($ch in $chars) {
- if (`character -isMember $ch $animPlugs[$ii]`) {
- $existingChars[$chCount++] = $ch;
- break;
- }
- }
- }
- }
- for ($ch in $chars) {
- $otherChars[size($otherChars)] = $ch;
- }
- }
-
- string $existingResult[];
- $existingResult = AWRemoveDuplicateStringsFromStringArray($existingChars);
- int $sizeExisting = size($existingResult);
- if ($sizeExisting == 0) {
- // none of the attributes were already in a character
- //
- string $otherResult[];
- $otherResult = AWRemoveDuplicateStringsFromStringArray($otherChars);
- if (size($otherResult) == 1) {
- // but one or more of the selected objects were in a character
- // so we will use the existing character
- //
- $sizeExisting = 1;
- $existingResult[0] = $otherResult[0];
- } else if (size($membersToAdd) > 0) {
- // create a new character
- //
- // first pick a name for the character
- //
- string $chName = "";
- string $shNames[] = `ls -sl -shortNames`;
- for ($obj in $membersToAdd) {
- string $memShort[] = `ls -o -shortNames $obj`;
- string $currName = ($memShort[0]+"Ch");
- if ($chName == "" || ($currName == $chName)) {
- $chName = $currName;
- } else {
- $chName = "multiCh";
- }
- }
-
- $newCharacter = `character -name $chName -empty`;
- character -e -add $newCharacter $membersToAdd;
- } else {
- if ($hierarchy) {
- // replace the selection
- //
- select -r $selInit;
- }
-
- if (size($otherResult) > 0) {
- error("The selected objects are from more than one character.");
- } else {
- error("No animated channels on the selected object(s).");
- }
- }
- }
-
- if ($hierarchy) {
- // replace the selection
- //
- select -r $selInit;
- }
-
- if ($sizeExisting == 1) {
- // use the existing character, add any of the attributes that
- // are not already in the character to this character
- //
- $newCharacter = $existingResult[0];
- for ($obj in $membersToAdd) {
- if (! `character -isMember $newCharacter $obj`) {
- character -e -add $newCharacter $obj;
- }
- }
- } else if ($sizeExisting > 1) {
- error("The selected objects are from more than one character.");
- }
-
- return $newCharacter;
- }
-